package com.cct.digitalarchapi.controller;

import com.alibaba.fastjson2.JSONObject;
import com.cct.digitalarchapi.common.CommonUtil;
import com.cct.digitalarchapi.common.Response;
import com.cct.digitalarchapi.pojo.ArchApplication;
import com.cct.digitalarchapi.pojo.ArchCategory;
import com.cct.digitalarchapi.service.ArchApplicationService;
import com.cct.digitalarchapi.service.ArchCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


/**
 * @FileName ArchApplicationController
 * @Description 档案借阅申请控制器
 * @Author Created by chenmingzhe
 * @Date 2023/11/19
 **/
@RestController
@RequestMapping(value = "/archApplication")
public class ArchApplicationController {
    @Autowired
    private ArchApplicationService archApplicationService;
    @Autowired
    private CommonUtil commonUtil;

    /**
     * 新增档案档案借阅
     */
    @RequestMapping(value = "/addArchApplication",method = RequestMethod.POST)
    public Response addArchApplication(@RequestBody ArchApplication archApplication){
        commonUtil.recordOperateLog("借阅了档案Id为"+archApplication.getArchMainId()+"的档案");
        return  archApplicationService.addArchApplication(archApplication);
    }

    /**
     * 查询借阅审批
     */
    @RequestMapping(value = "/qryArchApplication",method = RequestMethod.POST)
    public Response qryArchApplication(@RequestBody JSONObject obj){
        //1查询所有的借阅  2查询员工自己的借阅
        String type= obj.getString("type");
        String staffCode=obj.getString("staffCode");
        int pageNum=obj.getInteger("pageNum");
        int pageSize=obj.getInteger("pageSize");
        //传-1代表所有
        int appState=obj.getInteger("appState");
        String archTitle=obj.getString("archTitle");
        return  archApplicationService.qryArchApplication(type,staffCode,pageNum,pageSize,appState,archTitle);
    }
    /**
    *审批借阅
    */
    @RequestMapping(value = "/approveApplication",method = RequestMethod.POST)
    public Response approveApplication(@RequestBody ArchApplication archApplication){
        commonUtil.recordOperateLog("审批了id为"+archApplication.getRecid()+"档案借阅");
        return  archApplicationService.approveApplication(archApplication);
    }


}
